
package com.skcc.cop.mrtaxi.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.skcc.cop.mrtaxi.R;


public class TitleBar2 extends LinearLayout implements View.OnClickListener {
	 // ===========================================================
    // Constants
    // ===========================================================
    
    private static final String TAG = TitleBar2.class.getSimpleName();
    
    private final static String MENU = "menu";
    private final static String MOVE_MAP = "move_map";

    // ===========================================================
    // Fields
    // ===========================================================

    public OnTitleBarEventListener2 titlebarEventListener;
    
    private TextView title_textview;
    private ImageView menu_imageview;
    private ImageView move_map_imageview;
    
    private Context context;
    
    /**
     * 생성자
     * 
     * @param context
     * @param attrs
     */
    public TitleBar2(Context context, AttributeSet attrs) {
        super(context, attrs);
        
        this.context = context;
        
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View titlebar = inflater.inflate(R.layout.view_titlebar2, this, true);
        
        title_textview = (TextView) titlebar.findViewById(R.id.titlebar_title_textview);
        
        menu_imageview = (ImageView) titlebar.findViewById(R.id.titlebar_menu_imageview);
        menu_imageview.setTag(MENU);
        menu_imageview.setOnClickListener(this);
        
        move_map_imageview = (ImageView) titlebar.findViewById(R.id.titlebar_move_map_imageview);
        move_map_imageview.setTag(MOVE_MAP);
        move_map_imageview.setOnClickListener(this);
        
    }
    
    public void setTitle(String titleStr) {
    	title_textview.setText(titleStr);
    }
    
    public void setTitle(int resId) {
    	String title = this.context.getResources().getString(resId);
    	title_textview.setText(title);
    }
    
    public void showMenu() {
    	menu_imageview.setVisibility(View.VISIBLE);
    }
    
    public void hideMenu() {
    	menu_imageview.setVisibility(View.GONE);
    }
    
    public void showMoveMap() {
    	move_map_imageview.setVisibility(View.VISIBLE);
    }
    
    public void hideMoveMap() {
    	move_map_imageview.setVisibility(View.GONE);
    }
    
    /**
     * @param listener
     */
    public void setEventListener(OnTitleBarEventListener2 listener)
    {
    	titlebarEventListener = listener;
    }
    
    /**
     * callback 을 등록취소하는 메소드
     */
    public void removeEventListener()
    {
    	titlebarEventListener = null;
    }
    
    public void onClick(View v)
    {
        if (v.getTag().equals(MENU))
        {
        	titlebarEventListener.onMenuClicked();
        } else if (v.getTag().equals(MOVE_MAP))
        {
        	titlebarEventListener.onMoveMapClicked();
        } 
    }
    
    
    public interface OnTitleBarEventListener2 {
    	
        public void onMenuClicked();
        public void onMoveMapClicked();
       
    }
}
